<?php

class Content {

    private $ID;
    private $content_name;
    private $content_value;

    public function getByID($ID) {
        $list = array();
        $sql = "SELECT * FROM caws_content
                WHERE ID = '" . $ID . "'";
        $result = mysql_query($sql);
        $i = 0;
        while($rows = mysql_fetch_array($result)) {
            $list[$i]['ID'] = $rows['ID'];
            $list[$i]['content_name'] = $rows['content_name'];
            $list[$i]['content_value'] = $rows['content_value'];
            $i++;
        }
        return $list;
    }

    public function getByObj(Content $a) {
        $list = array();
        $sql = 'SELECT * FROM caws_content
                WHERE 1 ';

        $result = mysql_query($sql);
        $i = 0;
        while($rows = mysql_fetch_array($result)) {
            $list[$i]['ID'] = $rows['ID'];
            $list[$i]['content_name'] = $rows['content_name'];
            $list[$i]['content_value'] = $rows['content_value'];
            $i++;
        }
        return $list;
    }

    public function getRandom() {
        $data = "";
        $sql = "SELECT * FROM caws_content
                ORDER BY rand() LIMIT 1 ";

        $result = mysql_query($sql);
        while($rows = mysql_fetch_array($result)) {
            $data = base64_decode($rows['content_value']);
        }
        return $data;
    }

    public function insertData(Content $c) {
        $sql = "INSERT INTO caws_content
                (content_name , content_value)
                VALUES
                ('" . $c->content_name . "',
                 '" . $c->content_value . "') ";
        mysql_query($sql);
    }

    public function updateData(Content $c) {
        $sql = "UPDATE caws_content SET
                content_name = '" . $c->getContentName() . "' ,
                content_value = '" . $c->getContentValue() . "'
                WHERE ID = '" . $c->getID() . "' ";

        mysql_query($sql);
    }

    public function deleteData($ID) {
        $sql = "DELETE FROM caws_content WHERE ID = '" . $ID . "'";
        mysql_query($sql);
    }

    public function setID($ID) {
        $this->ID = $ID;
    }

    public function getID() {
        return $this->ID;
    }

    public function setContentName($name) {
        $this->content_name = $name;
    }

    public function getContentName() {
        return $this->content_name;
    }

    public function setContentValue($value) {
        $this->content_value = $value;
    }

    public function getContentValue() {
        return $this->content_value;
    }

}
?>
